def batchUpdate(updateFunc, datas, size=1000):
    cnt = 0
    processed = 0
    for start in range(0, len(datas), size):
        subDatas = datas[start: start + size]
        processed += len(subDatas)
        cnt += updateFunc(subDatas)
        print("update processed：%d / %d" % (processed, len(datas)))
    return cnt


def batchInsert(insertFunc, datas, size=1000):
    cnt = 0
    processed = 0
    for start in range(0, len(datas), size):
        subDatas = datas[start: start + size]
        processed += len(subDatas)
        cnt += insertFunc(subDatas)
        print("insert processed:%d / %d" % (processed, len(datas)))
    return cnt


def batchQuery(func, codes, size=1000):
    arr = []
    processed = 0
    for start in range(0, len(codes), size):
        subCodes = codes[start: start + size]
        processed += len(subCodes)
        arr.extend(func(subCodes))
        print("query processed：%d / %d " % (processed, len(codes)))
    return arr


def batchDelete(func, tableName, idx, size=1000):
    arr = []
    for start in range(0, len(idx), size):
        subIds = idx[start: start + size]
        arr.extend(func(tableName, subIds))
        print("delete processed：%d / %d " % (len(arr), len(idx)))
    return arr
